//
//  ReceiveFlowerView.m
//  BestLearning
//
//  Created by 星道 on 17/9/12.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "ReceiveFlowerView.h"

@implementation ReceiveFlowerView
{
    IBOutlet UIView *_contentView;
    IBOutlet UILabel *_msg;

    void (^_complete)();
}


+ (instancetype)receiveFlowerWithMsg:(NSString *)msg Complete:(void (^)())complete {

    return [[self alloc] initWithMsg:msg Complete:complete];
}

- (instancetype)initWithMsg:(NSString *)msg Complete:(void (^)())complete {

    self = [[[NSBundle mainBundle] loadNibNamed:[ReceiveFlowerView description] owner:nil options:nil] lastObject];
    if (self) {

        _msg.text = msg;
        _complete = complete;
        self.backgroundColor = ColorRGBA(0, 0, 0, 0);
        self.frame = [UIScreen mainScreen].bounds;
        [[[UIApplication sharedApplication].windows firstObject] addSubview:self];
        [self Show];
    }
    return self;
}



- (void)Show {

    _contentView.alpha = 0;
    _contentView.transform = CGAffineTransformMakeScale( 0.001, 0.001);
    [UIView animateWithDuration:0.3 animations:^{
        _contentView.alpha = 1;
        self.backgroundColor = ColorRGBA(0, 0, 0, 0.7);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3 animations:^{
            _contentView.transform = CGAffineTransformMakeScale( 1.5, 1.5);
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.2 animations:^{
                _contentView.transform = CGAffineTransformIdentity;
            }];
        }];
    }];
}

/** 确定 */
- (IBAction)Sure:(UIButton *)sender {

    [UIView animateWithDuration:0.2 animations:^{

        _contentView.transform = CGAffineTransformMakeScale( 1.5, 1.5);
    } completion:^(BOOL finished) {

        [UIView animateWithDuration:0.3 animations:^{

            _contentView.transform = CGAffineTransformMakeScale( 0.001, 0.001);
        } completion:^(BOOL finished) {

            [UIView animateWithDuration:0.3 animations:^{
                _contentView.alpha = 0;
                self.backgroundColor = ColorRGBA(0, 0, 0, 0);
            } completion:^(BOOL finished) {

                _complete ? _complete():nil;
                [self removeFromSuperview];
            }];
        }];
    }];
}

@end
